<template>
  <view class="shopping-cart-page">
    <view class="top-content">
      <view class="left-box">
        <text class="title" :style="{ fontSize: `${changeFontSize}rpx` }"
          >购物车</text
        >
      </view>
      <view class="right-box">
        <text class="yhq">优惠券</text>
        <text class="iconfont icon-weibiaoti--5"></text>
        <!-- 管理 -->
        <text class="gl">管理</text>
      </view>
    </view>
    <view class="bottom-content-box"> 请选择收货地址 </view>

    <scroll-view
      class="menu-content"
      scroll-y="true"
      @scroll="scrollFn"
      :show-scrollbar="false"
    >
      <view class="h-20"></view>
      <view class="list-box">
        <view
          class="top-fixed"
          :class="{ fixedStyle }"
          :style="{ top: setFixedTop + 'px' }"
        >
          <tab009></tab009>
        </view>
        <hstab010></hstab010>
        <view class="pdlr-10">
          <list004
            class="mb-10"
            v-for="item in weipinhuiCart"
            :key="item.id"
            :showData="item"
          ></list004>
        </view>
      </view>
      <view class="bg-grey">
        <view class="mrb-30">
          <booth004></booth004>
        </view>
        <view class="panel-list-item">
          <!-- 动态每个面板组件 -->
          <panel006
            class="list-item"
            :showData="itemData"
            v-for="itemData in weipinhuiBigData"
            :key="itemData.id"
          >
          </panel006>
        </view>
      </view>
    </scroll-view>
    <view class="fb">
      <booth006></booth006>
    </view>
  </view>
</template>

<script>
import {
  defineComponent,
  reactive,
  toRefs,
  getCurrentInstance,
  onMounted,
} from "vue";
import { weipinhuiCart, weipinhuiBigData } from "@/common/simulatedData.js";

export default defineComponent({
  name: "",
  props: {},
  components: {},
  setup() {
    const data = reactive({
      fontSize: 45,
      changeFontSize: 45,
      weipinhuiCart,
      weipinhuiBigData,
      fixedStyle: false,
      scrollTop: 0,
      actualScrollTop: 0,
      setFixedTop: 0,
    });
    onMounted(() => {
      getScrollInfo();
      getTopFixedInfo();
    });
    // 获取滚动元素位置信息
    const { proxy } = getCurrentInstance();
    // 获取顶部tabs滚动元素信息
    const getScrollInfo = () => {
      const query = uni.createSelectorQuery().in(proxy);
      query
        .select(".uni-scroll-view-content")
        .boundingClientRect((ele) => {
          console.log(ele.top);
          data.scrollTop = ele.top;
        })
        .exec();
    };
    const getTopFixedInfo = () => {
      const query = uni.createSelectorQuery().in(proxy);
      query
        .select(".h-20")
        .boundingClientRect((ele) => {
          data.actualScrollTop = ele.height;
        })
        .exec();
    };

    const scrollFn = (e) => {
      if (e.detail.scrollTop >= data.actualScrollTop) {
        data.fixedStyle = true;
        data.setFixedTop = data.scrollTop - 10;
        data.changeFontSize = 35;
      } else {
        data.fixedStyle = false;
        data.setFixedTop = 0;
        data.changeFontSize = 45;
      }
    };
    return {
      scrollFn,
      ...toRefs(data),
    };
  },
});
</script>

<style scoped lang="less">
.shopping-cart-page {
  position: relative;
  height: calc(100vh - 100rpx);
  width: 100%;
  //   渐变
  background: #f7f7f7;
  padding-top: 80rpx;
  box-sizing: border-box;
  .top-content {
    display: flex;
    justify-content: space-between;
    padding: 0 20rpx;
    .left-box {
      display: flex;
      flex-direction: column;
    }
    .right-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .yhq {
        font-size: 20rpx;
        color: #ff0777;
        border: 1rpx solid #ff5ba5;
        box-sizing: border-box;
        border-radius: 6rpx;
        padding: 0 8rpx;
      }
      .icon-weibiaoti--5 {
        font-size: 32rpx;
        padding: 0 20rpx;
        border-left: 1rpx solid #7d7d7d;
        border-right: 1rpx solid #7d7d7d;
        margin: 0 20rpx;
        color: #7e7e7e;
      }
      .gl {
        font-size: 28rpx;
        color: #7e7e7e;
      }
    }
  }
  .bottom-content-box {
    padding: 0 20rpx;
    font-size: 24rpx;
    color: #7e7e7e;
  }
  .menu-content {
    height: calc(100vh - 370rpx);
    box-sizing: border-box;
    overflow: hidden;
    position: absolute;
    border-radius: 35rpx 35rpx 0 0;
    padding-top: 10rpx;
    .list-box {
      padding: 0 10rpx;
      padding-bottom: 0rpx;
      // 渐变 透明
      background: linear-gradient(to top, #f7f7f7, #ffffff 100%);
      padding-top: 86rpx;
      border-radius: 35rpx 35rpx 0 0;
      position: relative;
      .top-fixed {
        border-radius: 35rpx 35rpx 0 0;
        overflow: hidden;
        background: #ffffff;
        padding: 20rpx;
        z-index: 90;
        width: 100%;
        box-sizing: border-box;
        position: absolute;
        top: 0rpx;
        left: 0rpx;
        &.fixedStyle {
          position: fixed;
        }
      }
    }
    .panel-list-item {
      width: 100%;
      column-count: 2;
      column-gap: 20rpx;
      row-gap: 0rpx;

      // 行间距
      padding: 0 10rpx;
      box-sizing: border-box;
      .list-item {
        margin-bottom: 20rpx;
      }
    }
  }
}
</style>
